package com.coffee.monitorClient;

import java.util.Timer;
import java.util.TimerTask;

import org.hyperic.sigar.SigarException;

/**
 *
 */
public class Main 
{
	
//	{
//	    "apikey": "123",
//	    "method": "123",
//	    "device": 10,
//	    "sensor": 10,
//	    "timestamp": "123",
//	    "value": "123"
//	}
	//传感器id
	static final String[] sensorId_cpu = new String[]{"1","2"};
	static final String[] sensorId_disk = new String[]{"3","4","5"};
	//apikey
	static final String apikey = "1";
	static final String device = "1";
	static String[] message=null;
    public static void main( String[] args )
    {
        Client main=new Client();
        main.start();
        Timer timer=new Timer(true);
        TimerTask tt = new TimerTask() {
            @Override
            public void run() {
            	 buildCpu();
	        	 for (String string : message) {
	        		 if (string==null) {
							continue;
		        		 }
	        		 try {
						Thread.sleep(100);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
	        		 Client.sendMessage(string);
				 }
	        	 buildDisk();
	        	 for (String string : message) {
	        		 if (string==null) {
						continue;
	        		 }
	        		 try {
	        			 Thread.sleep(100);
	        		 } catch (InterruptedException e) {
	        			 e.printStackTrace();
	        		 }
	        		 Client.sendMessage(string);
	        	 }
            }
        };
        timer.schedule(tt, 1000, 60*1000);
    }
    static void buildCpu(){
    	try {
    		message=SystemInfo.buildCpu(sensorId_cpu, apikey,device);
		} catch (SigarException e) {
			e.printStackTrace();
		}
    }
    static void buildDisk(){
    	try {
    		message=SystemInfo.buildDisk(sensorId_disk, apikey,device);
    	} catch (SigarException e) {
    		e.printStackTrace();
    	}
    }
}
